Skip to content

Auto-save launched project to recent projects and canonicalize paths - #1208

Open
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:feat-auto-save-recent-project
Open

Auto-save launched project to recent projects and canonicalize paths#1208
nordicnode wants to merge 1 commit into
CodebuffAI:mainfrom
nordicnode:feat-auto-save-recent-project

Conversation

@nordicnode

Copy link
Copy Markdown

Auto-save launched project to recent projects and canonicalize paths

Summary

• Automatically records the launched project in recent-projects.json on CLI boot (cli/src/index.tsx) whenever the user starts Freebuff directly inside a project (i.e. when not showing the project picker).
• Previously, saveRecentProject was only invoked inside onSelectProject when navigating through the project picker, meaning standard launches (cd ~/my-project && freebuff) never populated "Recent Projects".
• Canonicalizes projectPath with path.resolve() in saveRecentProject and removeRecentProject (cli/src/utils/recent-projects.ts) to avoid duplicate entries and filtering mismatches caused by relative paths or trailing slashes.
• Switched recent-projects.ts to import getConfigDir from ./config-dir instead of ./auth to avoid pulling in the entire auth/api stack.
• Adds comprehensive unit tests in cli/src/__tests__/utils/recent-projects.test.ts covering path canonicalization, disk validation filtering, LRU-style capping, project removal, and clearing.

Test plan

[✓] bun test --config=/dev/null src/__tests__/utils/recent-projects.test.ts — 8 pass, 0 fail
[✓] bun run --cwd cli typecheck — 0 errors
[✓] PR hygiene check passed

@codebuff-team

Copy link
Copy Markdown
Contributor

Good bug fix. The core issue you found is real: saveRecentProject was only wired into onSelectProject, so direct launches from inside a project (cd ~/my-project && freebuff) never landed in "Recent Projects" — this is exactly the kind of small papercut worth porting.

The canonicalization change in cli/src/utils/recent-projects.ts (using path.resolve in both saveRecentProject and removeRecentProject, and filtering by resolved path rather than raw string) is the right fix for the trailing-slash / relative-path duplicate-entry bug, and it's covered well by the new tests (recent-projects.test.ts), including the trailing-slash canonicalization case and the LRU cap test.

Switching the getConfigDir import from ./auth to ./config-dir is a nice, unrelated-but-welcome cleanup that avoids pulling the auth/api stack into a simple filesystem utility — worth calling out explicitly in the commit message if you split this in the private tree, since reviewers may want it as a separate atomic change.

One thing I can't verify from the diff alone: the cli/src/index.tsx hunk assumes projectRoot is already in scope at that point in main() and that saveRecentProject is already imported (both plausible given the existing onSelectProject usage, but worth double-checking against the actual file). Also worth considering whether saveRecentProject should be skipped when the resolved path isn't a valid project root at all (e.g. arbitrary directories where shouldShowProjectPicker still returns false) — the existence check in saveRecentProject covers the disk-existence case, but not necessarily "is this actually a project".

Overall: focused, tested, low blast radius. Good work for a first contribution.

@codebuff-team codebuff-team added bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree labels Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:triaged Classified by the community triage bot pr:port-candidate Worth porting into the private source tree

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants